import { ref } from 'vue';
import { EmitsType } from '../src/types';

export const useEditCell = (useEditCellEmits: EmitsType<'confirm' | 'cancle'>) => {
  const currentEdit = ref<string>('');
  // 编辑单元格
  const clickEditIcon = (scope: any) => {
    currentEdit.value = scope.$index + scope.column.id;
  };

  const closeEdit = (scope: any) => {
    currentEdit.value = '';
    useEditCellEmits('cancle', scope);
  };

  const confirmEdit = (scope: any) => {
    currentEdit.value = '';
    useEditCellEmits('confirm', scope);
  };

  return {
    currentEdit,
    clickEditIcon,
    closeEdit,
    confirmEdit,
  };
};
